BASE = ucosii_test
ELF_TARGET = $(BASE).elf
BIN_TARGET = $(BASE).bin
C_SRCS = Kernel/ucos_ii.c \
		 Kernel/os_dbg.c \
		 Arm/os_cpu_c.c \
		 Bsp/bsp.c\
		 Bsp/printf_stdarg.c\
		 App/app.c

C_OBJS = ${C_SRCS:.c=.o}
ASM_SRCS = start.S \
		   Arm/os_cpu_a.S

ASM_OBJS = ${ASM_SRCS:.S=.o}

TC_PREFIX=arm-eabi-
CC=${TC_PREFIX}gcc
LD=${TC_PREFIX}gcc
OBJDUMP=${TC_PREFIX}objdump
OBJCOPY=${TC_PREFIX}objcopy
READELF=${TC_PREFIX}readelf
NM=${TC_PREFIX}nm

CFLAGS= -Wall -Wstrict-prototypes -Wno-trigraphs -pipe -march=armv4t -mtune=arm920t -g
INCLUDES = -IBsp/ -IApp/ -IKernel/ -IArm/
LDFLAGS= -nostdlib -N -p -Wl,-X -T${BASE}.lds -lgcc

.PHONY: all clean extra

all:: ${ELF_TARGET} ${BIN_TARGET}

extra: all
	${OBJDUMP} -xS ${ELF_TARGET} > ${BASE}.s
	${READELF} -a ${ELF_TARGET} > ${BASE}.r
	${NM} ${ELF_TARGET} > ${BASE}.n

${ELF_TARGET}: ${ASM_OBJS} ${C_OBJS} 
	${LD} -o $@ $^ ${LDFLAGS}

${BIN_TARGET}: ${ELF_TARGET}
	${OBJCOPY} -O binary ${ELF_TARGET} ${BIN_TARGET}

${C_OBJS}: %.o: %.c
	${CC} ${CFLAGS} ${INCLUDES} -o $@ -c $< 

${ASM_OBJS}: %.o: %.S
	${CC} ${CFLAGS} ${INCLUDES} -o $@ -c $< 

clean:
	-rm -f *~ ${ELF_TARGET} ${BASE}.s ${BASE}.r ${BASE}.n ${BIN_TARGET}
	-find ./ -name "*.o"|xargs rm -f

